package com.olap.starter.controller.admin.luckycola.utils;

import lombok.Data;

import java.sql.ResultSet;
import java.sql.SQLException;

@Data
public class MySqlQuery {
    private String commentSql = "select COLUMN_NAME,COLUMN_COMMENT from information_schema.COLUMNS where TABLE_SCHEMA = ? ";
    private String iTableSql = "select table_schema,table_name,table_comment from information_schema.tables where table_schema = ?";
    private String iFieldSql = "select COLUMN_NAME as COLUMN_NAME_OLD,COLUMN_COMMENT,COLUMN_TYPE,COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE,COLUMN_DEFAULT, (CASE WHEN column_key = 'PRI' THEN 1 ELSE 0 END) AS is_pk from information_schema.COLUMNS where TABLE_SCHEMA = ? and TABLE_NAME = ?";

    public String tablesSql() {
        return "show table status WHERE 1=1 ";
    }

    public String tableFieldsSql() {
        return "show full fields from `%s`";
    }

    public String tableName() {
        return "NAME";
    }

    public String tableComment() {
        return "COMMENT";
    }

    public String fieldName() {
        return "FIELD";
    }

    public String fieldType() {
        return "TYPE";
    }

    public String fieldComment() {
        return "COMMENT";
    }

    public String fieldKey() {
        return "KEY";
    }

    public boolean isKeyIdentity(ResultSet results) throws SQLException {
        return "auto_increment".equals(results.getString("Extra"));
    }

    public String getCatalog() {
        return " SELECT DATABASE(); ";
    }
}
